package cn.lingyangwl.agile.common.core.config;

import cn.lingyangwl.agile.model.constants.RequestCons;
import cn.lingyangwl.agile.model.constants.SecurityCons;
import cn.lingyangwl.agile.common.core.exception.enums.GlobalErrorEnum;
import cn.lingyangwl.framework.core.response.ResponseFormatConfig;
import cn.lingyangwl.framework.core.response.format.ResponseCode;
import cn.lingyangwl.framework.core.response.format.ResponseFormat;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author shenguangyang
 */
@Configuration
@AutoConfigureBefore(ResponseFormatConfig.class)
public class MyResponseFormatConfig {
    @Bean
    public ResponseFormat responseFormat() {
        ResponseCode responseCode = ResponseCode.builder()
                .fail(GlobalErrorEnum.FAIL.getCode()).success(GlobalErrorEnum.SUCCESS.getCode()).build();
        ResponseFormat format = new ResponseFormat(responseCode);
        format.setMessageName("message");
        format.setDataName("data");
        format.setCodeName("code");
        // 只要识别到这些头部信息, 就不使用包装格式头
        format.setNoWrapFormatHeader(SecurityCons.HEADER_FROM_IN + ";" + RequestCons.Headers.CLIENT_SIGN_API);
        return format;
    }
}
